package chrome.entity;

import chrome.Interface.SerializeObj;
import com.alibaba.fastjson.JSONObject;
import commons.entity.Constant;
import commons.entity.NativeCp;
import commons.util.GameUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class ChromeAccounts implements SerializeObj {
    private List<ChromeAccount> caList;

    private static final Logger LOGGER = LogManager.getLogger(ChromeAccount.class);

    public static ChromeAccounts chromeAccouonts;

    public static ChromeAccounts getInstance() {
        if (chromeAccouonts == null) {
            String filepath = NativeCp.getUserDir() + "/config/" + Constant.CHROME + "/ChromeAccounts.json";
            chromeAccouonts = JSONObject.parseObject(GameUtil.getJsonString(filepath), ChromeAccounts.class);
        }
        return chromeAccouonts;
    }

    public List<ChromeAccount> getCaList() {
        return caList;
    }

    public void setCaList(List<ChromeAccount> caList) {
        this.caList = caList;
    }

    @Override
    public Object GenerateJsonObj() {
        ChromeAccount c;
        ChromeAccounts cs = new ChromeAccounts();
        List<ChromeAccount> caList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            c = new ChromeAccount();
            c.setAcName("");
            c.setHomeClickLoc(new Point());
            c.setSingnWebAddressClickLoc(new Point());
            c.setSignPageSlicePoint(new Point());
            c.setSignPageRollButton(new Point());
            caList.add(c);
        }
        cs.setCaList(caList);
        return cs;
    }
}
